package cn.itsource.service.impl;

import cn.itsource.mapper.DriverPointMapper;
import cn.itsource.pojo.domain.DriverPoint;
import cn.itsource.pojo.vo.RealPointVo;
import cn.itsource.service.IDriverPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 📖：beishan
 * 🗓️：2024/4/17 9:54
 * =====================
 */
@Service
public class DriverPointServiceImpl implements IDriverPointService {
    @Autowired
    private DriverPointMapper driverPointMapper;
    @Override
    public void save(DriverPoint point) {
        driverPointMapper.save(point);
    }

    @Override
    public List<DriverPoint> selectByOrderNo(String orderNo) {
        return driverPointMapper.selectByOrderNo(orderNo);
    }

    @Override
    public List<RealPointVo> locationByOrderId(String orderId) {
        List<RealPointVo> realPointVos = new ArrayList<>();
        RealPointVo pointVo;
        List<DriverPoint> driverPoints = selectByOrderNo(orderId);
        if(driverPoints.size() == 0){
            return null;
        }
        for (DriverPoint driverPoint : driverPoints) {
            pointVo = new RealPointVo();
            pointVo.setLatitude(driverPoint.getLatitude());
            pointVo.setLongitude(driverPoint.getLongitude());
            realPointVos.add(pointVo);
        }
        return realPointVos;
    }
}
